package modelo;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
import javax.faces.model.SelectItem;

import dao.AreaTematicaDao;
import excepciones.DaoException;

import beans.SeleccionPerfilBean;

@FacesConverter( value="areasTematicasConverter" )
public class AreasTematicasConverter implements Converter{

	public String getAsString(FacesContext context, UIComponent component, Object value) {
        // Convert the Foo object to its unique String representation.
        return (value instanceof AreaTematica) ? ((AreaTematica) value).getNombre(): null;

    }

	@Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
		
		AreaTematicaDao areaTematicaDao = new AreaTematicaDao();
		AreaTematica areaTematica= null;
		try {
			areaTematica = (AreaTematica) areaTematicaDao.encontrarPorNombre(value);
			areaTematicaDao.closeEntityManager();
		} catch (DaoException e) {			
			e.printStackTrace();
		}
		
		//System.out.println(value);
        return areaTematica;
	}

}
